import {
  Body,
  Controller,
  Get,
  Param, ParseUUIDPipe,
  Patch,
  Query,
  UseGuards,
} from '@nestjs/common';
import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import {
  ArticleAdminIndexDto,
  ArticleAdminUpdateDto,
} from './article.dto';
import { ArticleService } from './article.service';
import { getPager } from "@/common/pager-response";
import { AdminAuthGuard } from "@/common/auth/admin-auth.guard";
import {
  ArticleAdminIndexResult,
  ArticleAdminShowNormal,
} from '@/module/article/article.result';
import { PageResult } from "common/interface";
import { ApiPaginatedOkResponse } from "@/common/pager-response/api-paginated-ok-response.decorator";

@Controller('/v1/admin/articles')
@ApiTags('Article_admin')
@UseGuards(AdminAuthGuard)
export class ArticleV1AdminController {
  constructor(private readonly articleService: ArticleService) {
  }

  @Get('/')
  @ApiOperation({ summary: '列表查询' })
  @ApiPaginatedOkResponse(ArticleAdminIndexResult)
  async index(@Query() query: ArticleAdminIndexDto): Promise<PageResult<ArticleAdminIndexResult>> {
    const res = await this.articleService.adminIndex(query);
    return getPager(res[0],res[1]);
  }

  @Get('/:uuid')
  @ApiOperation({ summary: '详情' })
  @ApiOkResponse({ type: ArticleAdminShowNormal })
  async show(@Param('uuid', ParseUUIDPipe) uuid: string): Promise<ArticleAdminShowNormal | null> {
    const res = await this.articleService.adminShowNormal(uuid);
    return res;
  }


  @Patch('/:uuid')
  @ApiOperation({ summary: '修改' })
  async update(
    @Body() body: ArticleAdminUpdateDto,
    @Param('uuid', ParseUUIDPipe) uuid: string,
  ): Promise<void> {
    await this.articleService.adminUpdate(body, uuid);
    return;
  }

}
